home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 24
/
Mac Magazin and MacEasy Magazine CD - Issue 24.iso
/
Online
/
Drag-n-Drop-Email-as.05
/
Drag n Drop Email (text)
< prev
next >
Wrap
Text File
|
1996-07-17
|
8KB
|
287 lines
property isitSet : false
property useSpeech : "unspecified"
property whichVoice : {"Fred"}
property emailHost : ""
property returnAddress : ""
property userName : ""
property userPassword : ""
global serverResponse, sss, inBox
on run
if not isitSet then
configure()
end if
set closeAfter to false
if not (PPPopened) then
set closeAfter to true
openPPP (getPPPServer)
repeat while not (PPPopened)
end repeat
end if
set sss to (tcp connect to host emailHost port 110)
try
readresponse(sss)
tcp write data "USER " & userName & return stream sss using ISO88591
readresponse(sss)
tcp write data "PASS " & userPassword & return stream sss using ISO88591
readresponse(sss)
tcp write data "STAT" & return stream sss using ISO88591
readresponse(sss)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set messageCount to text item 2 of serverResponse as integer
set AppleScript's text item delimiters to oldDelimiters
if messageCount ≠ 1 then
if messageCount = 0 then
if useSpeech = "yes" then
speak "There are no messages" voice whichVoice
end if
set dialogResponse to (display dialog "There are no messages for " & userName & "." buttons {"OK"} default button "OK")
else
if useSpeech = "yes" then
speak "There are " & messageCount & " new messages" voice whichVoice
end if
set dialogResponse to (display dialog "There are " & messageCount & " e-mail messages for " & userName & "." buttons {"OK", "Get Mail"} default button "Get Mail")
end if
else
if useSpeech = "yes" then
speak "There is one new message" voice whichVoice
end if
set dialogResponse to (display dialog "There is " & messageCount & " e-mail message for " & userName & "." buttons {"OK", "Get Mail"} default button "Get Mail")
end if
if (button returned of dialogResponse = "Get Mail") then
set currentMessage to 1
tell application "Finder"
if not (folder "AppleScript Inbox" of desktop exists) then
set inBox to (make folder with properties {name:"AppleScript Inbox"}) as string
else
set inBox to (folder "AppleScript Inbox" of desktop) as string
end if
end tell
repeat while currentMessage ≤ messageCount
getMail(currentMessage)
set currentMessage to currentMessage + 1
end repeat
end if
tcp close stream sss
on error msg number num
tcp close stream sss
display dialog "Script Aborted." buttons {"OK"} default button "OK"
set isitSet to false
quit
end try
if closeAfter = true then
if (PPPopened) = true then
closePPP with hard close
end if
end if
end run
on open (docList)
set messageCount to (count of docList) as string
if not isitSet then
configure()
end if
set closeAfter to false
if not (PPPopened) then
set closeAfter to true
openPPP (getPPPServer)
repeat while not (PPPopened)
end repeat
end if
set LF to ASCII character (10)
set CR to return
set CRLF to CR & LF
set sss to (tcp connect to host emailHost port 25)
readresponse(sss)
tcp write data "HELO " & (tcp my address) & return stream sss using ISO88591
readresponse(sss)
try
repeat with aFile in docList
set aFile to contents of aFile
tcp write data "mail from: " & userName & return ¬
stream sss using ISO88591
readresponse(sss)
set afilename to aFile as string
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theFileName to last text item of afilename
set AppleScript's text item delimiters to oldDelimiters
set emailSubject to theFileName as text
open for access afilename
set sendToaddress to (read afilename before return)
set mailContents to (read afilename)
close access afilename
tcp write data "rcpt to: " & sendToaddress & return ¬
stream sss using ISO88591
readresponse(sss)
tcp write data "data" & return stream sss using ISO88591
readresponse(sss)
tcp write data "To: " & sendToaddress & return stream sss using ISO88591
tcp write data "Subject: " & emailSubject & return stream sss using ISO88591
tcp write data mailContents & return stream sss using ISO88591
tcp write data "." & return stream sss using ISO88591
readresponse(sss)
end repeat
if useSpeech = "yes" then
if messageCount = "1" then
speak messageCount & " message has been sent" voice whichVoice
else
speak messageCount & " messages have been sent" voice whichVoice
end if
end if
tcp close stream sss
if closeAfter = true then
if (PPPopened) = true then
closePPP with hard close
end if
end if
return
on error msg number num
tcp close stream sss
display dialog "Script Aborted." buttons {"OK"} default button "OK"
set isitSet to false
quit
end try
end open
on getMail(currentMessage)
set LF to ASCII character (10)
set nowTotal to (time string of (current date))
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set nowHour to text item 1 of nowTotal
set nowMin to text item 2 of nowTotal
set nowSec to text item 3 of nowTotal
set nowString to nowHour & "h" & nowMin & "m" & nowSec & "s"
set AppleScript's text item delimiters to oldDelimiters
set currentFilename to inBox & "Message #" & currentMessage & " " & nowString
open for access file currentFilename with write permission
tcp write data "RETR " & currentMessage & return stream sss using ISO88591
readresponse(sss)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set messageSize to text item 2 of serverResponse as integer
set AppleScript's text item delimiters to oldDelimiters
repeat until (bytes waiting of (tcp status stream sss) = 0)
write (tcp read stream sss using ISO88591) to file currentFilename starting at eof
set beginWait to time of (current date)
repeat until time of (current date) > beginWait + 1
end repeat
end repeat
close access file currentFilename
tcp write data "DELE " & currentMessage & return stream sss using ISO88591
readresponse(sss)
end getMail
on readresponse(sstream)
set LF to ASCII character (10)
repeat until (tcp ahead characters LF stream sstream)
end repeat
set serverResponse to (tcp read until characters LF stream sstream using ISO88591)
end readresponse
on configure()
set defaultInfo to {"user:pAssWoRD@mail.wherever.com"}
checkOSAX({"TCP/IP Scripting Addition", "MacPPP Control"})
if result = false then
display dialog "Certain essential Scripting Additions are missing." & return ¬
& "See the enclosed ReadMe for more information." buttons {"OK"} default button "OK"
quit
end if
set dialogResponse to (display dialog "Enter a username, password, and mail server:" default answer defaultInfo)
if (button returned of dialogResponse ≠ "OK") then
display dialog "Script Aborted." buttons {"OK"} default button "OK"
quit
else
set userInfo to text returned of dialogResponse
if userInfo = defaultInfo then
display dialog "Script Aborted." buttons {"OK"} default button "OK"
quit
end if
end if
set oldDelims to text item delimiters of AppleScript
set text item delimiters of AppleScript to {":"}
set userName to first text item of userInfo
set intermediateStep to last text item of userInfo
set text item delimiters of AppleScript to {"@"}
set userPassword to first text item of intermediateStep
set returnAddress to last text item of intermediateStep
set emailHost to last text item of intermediateStep
set text item delimiters of AppleScript to oldDelims
if useSpeech = "unspecified" then
checkOSAX({"Speech"})
if result = false then
set useSpeech to "no"
else
set useSpeech to "yes"
if "Fred" is not in (list voices) then
set whichVoice to "Bruce"
if "Bruce" is not in (list voices) then
set useSpeech to "no"
end if
end if
end if
end if
set isitSet to true
end configure
on checkOSAX(OSAXTest)
tell application "Finder"
set OSAXList to name of every item of folder "Scripting Additions" of extensions folder
set failedTest to ""
repeat with oneItem in OSAXTest
if oneItem is not in OSAXList then
set failedTest to failedTest & tab & oneItem & return
end if
end repeat
if failedTest is "" then
return true
else
return false
end if
end tell
end checkOSAX
on quit
continue quit
end quit